<!DOCTYPE html>
<html lang="zh-Hans">
<head>

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->


<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<meta name="author" content="maobaolong" />
<meta name="renderer" content="webkit">
<meta name="google" value="notranslate">



<meta name="description" content="简介这年头要是没有个博客都不好意思给别人说你是程序员，我用XX笔记呀，不行吗？不行，这玩意儿要么不能公开分享，要么公开分享要会员，现在到处都是开源，自己学到了东西都不能分享给需要帮助的人，真是伤心呀。那么今天就来聊聊当你用Hexo搭建了博客，怎么自动更新呢，大家都知道Hexo是需要手动生成HTML静态网页的，虽然命令很少，但是每次写完博客先得推送到git然后在生成静态文件，再推送到服务器，想想我这">
<meta property="og:type" content="article">
<meta property="og:title" content="手把手教你使用Travis CI自动部署你的Hexo博客到Github上">
<meta property="og:url" content="/2017/01/20/工具使用/github_blog/github_hexo_travis/index.html">
<meta property="og:site_name" content="maobaolong">
<meta property="og:description" content="简介这年头要是没有个博客都不好意思给别人说你是程序员，我用XX笔记呀，不行吗？不行，这玩意儿要么不能公开分享，要么公开分享要会员，现在到处都是开源，自己学到了东西都不能分享给需要帮助的人，真是伤心呀。那么今天就来聊聊当你用Hexo搭建了博客，怎么自动更新呢，大家都知道Hexo是需要手动生成HTML静态网页的，虽然命令很少，但是每次写完博客先得推送到git然后在生成静态文件，再推送到服务器，想想我这">
<meta property="og:updated_time" content="2017-01-20T06:07:14.044Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="手把手教你使用Travis CI自动部署你的Hexo博客到Github上">
<meta name="twitter:description" content="简介这年头要是没有个博客都不好意思给别人说你是程序员，我用XX笔记呀，不行吗？不行，这玩意儿要么不能公开分享，要么公开分享要会员，现在到处都是开源，自己学到了东西都不能分享给需要帮助的人，真是伤心呀。那么今天就来聊聊当你用Hexo搭建了博客，怎么自动更新呢，大家都知道Hexo是需要手动生成HTML静态网页的，虽然命令很少，但是每次写完博客先得推送到git然后在生成静态文件，再推送到服务器，想想我这">

<link rel="apple-touch-icon" href= "/blog//apple-touch-icon.png">


    <link rel="alternative" href="/atom.xml" title="maobaolong" type="application/atom+xml">



    <link rel="shortcut icon" href="/blog//resources/avatar.jpg">



    <link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">



    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/blog/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>手把手教你使用Travis CI自动部署你的Hexo博客到Github上 | maobaolong</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: true,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: true
    }
</script>


    <script>
        yiliaConfig.jquery_ui = [true, "//cdn.bootcss.com/jqueryui/1.10.4/jquery-ui.min.js", "//cdn.bootcss.com/jqueryui/1.10.4/css/jquery-ui.min.css"];
    </script>



    <script> yiliaConfig.rootUrl = /blog/; </script>





    <script>
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "//hm.baidu.com/hm.js?a4938c90e05043bd9774ff12368e45aa";
            var s = document.getElementsByTagName("script")[0]; 
            s.parentNode.insertBefore(hm, s);
        })();
    </script>


</head>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/blog/" class="profilepic">
            <img src="/blog//resources/avatar.jpg" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/blog/">maobaolong</a></h1>
        </hgroup>

        
        <p class="header-subtitle">神龙</p>
        

        
            <form id="search-form">
            <input type="text" id="local-search-input" name="q" placeholder="search..." class="search form-control" autocomplete="off" autocorrect="off" searchonload="false" />
            <i class="fa fa-times" onclick="resetSearch()"></i>
            </form>
            <div id="local-search-result"></div>
            <p class='no-result'>No results found <i class='fa fa-spinner fa-pulse'></i></p>
        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/blog//blog/../archives">所有文章</a></li>
                        
                            <li><a href="/blog//blog/../tags/">标签云</a></li>
                        
                            <li><a href="/blog//blog/../about/">留言板</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="/blog/maobaolong@139.com" title="Email"></a>
                            
                                <a class="fa 新浪微博" href="//weibo.com/maobaolong" title="新浪微博"></a>
                            
                                <a class="fa GitHub" href="//github.com/maobaolong" title="GitHub"></a>
                            
                                <a class="fa QQ" href="/blog/307499405" title="QQ"></a>
                            
                                <a class="fa CSDN" href="http://blog.csdn.net/maobaolong" title="CSDN"></a>
                            
                                <a class="fa hacpai" href="https://hacpai.com/member/maobaolong" title="hacpai"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/Hexo/">Hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/Travis-CI/">Travis CI</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/alluxio/">alluxio</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bigdata/">bigdata</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/centos/">centos</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/en/">en</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/etcd/">etcd</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/">git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/github-blog/">github_blog</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hadoop/">hadoop</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/haproxy/">haproxy</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hive/">hive</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/html/">html</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/idea/">idea</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/">java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/jenkins/">jenkins</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/jquery/">jquery</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/kafka/">kafka</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/maven/">maven</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/mongodb/">mongodb</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/mysql/">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/nginx/">nginx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/playframework/">playframework</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/protobuffers/">protobuffers</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/rpc/">rpc</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/scrt/">scrt</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/seafile/">seafile</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/spark/">spark</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/springMVC/">springMVC</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/sql/">sql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/thrift/">thrift</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/tomcat/">tomcat</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/ubuntu/">ubuntu</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/velocity/">velocity</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/vim/">vim</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/web/">web</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/xss/">xss</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/yarn/">yarn</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/zookeeper/">zookeeper</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/元宝/">元宝</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/分布式/">分布式</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/容器/">容器</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/工具使用/">工具使用</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/幼儿健康/">幼儿健康</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/技术学习/">技术学习</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/持续集成/">持续集成</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/数据库/">数据库</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/树莓派/">树莓派</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/框架/">框架</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/模板引擎/">模板引擎</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/正则表达式/">正则表达式</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/育儿经/">育儿经</a></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/自动部署/">自动部署</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="http://maobaolong.f3322.net/seafile">seafile</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://maobaolong.f3322.net:9999">home</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://maobaolong.gicp.net:9999">herHome</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://maobaolong.f3322.net/blog">个人博客</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://blog.csdn.net/maobaolong">CSDN博客</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://hacpai.com/member/maobaolong">黑客派</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">多学多记&lt;br&gt;&lt;br&gt;多分享&lt;br&gt;谢谢大家</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">maobaolong</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/blog/" class="profilepic">
                <img src="/blog//resources/avatar.jpg" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/blog/" title="回到主页">maobaolong</a></h1>
            </hgroup>
            
            <p class="header-subtitle">神龙</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/blog/../archives">所有文章</a></li>
                
                    <li><a href="/blog/../tags/">标签云</a></li>
                
                    <li><a href="/blog/../about/">留言板</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="/blog/maobaolong@139.com" title="Email"></a>
                            
                                <a class="fa 新浪微博" target="_blank" href="//weibo.com/maobaolong" title="新浪微博"></a>
                            
                                <a class="fa GitHub" target="_blank" href="//github.com/maobaolong" title="GitHub"></a>
                            
                                <a class="fa QQ" target="_blank" href="/blog/307499405" title="QQ"></a>
                            
                                <a class="fa CSDN" target="_blank" href="http://blog.csdn.net/maobaolong" title="CSDN"></a>
                            
                                <a class="fa hacpai" target="_blank" href="https://hacpai.com/member/maobaolong" title="hacpai"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
</nav>
      <div class="body-wrap"><article id="post-工具使用/github_blog/github_hexo_travis" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/" class="article-date">
      <time datetime="2017-01-20T05:56:59.000Z" itemprop="datePublished">2017-01-20</time>
</a>

 
    <a href="/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/#comments" title="查看评论">
        <i class="fa fa-comments-o" aria-hidden="true"></i>
        <span class="count-comment"></span>
        
            <span class="ds-thread-count" "></span>
        
        
    </a>

    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      手把手教你使用Travis CI自动部署你的Hexo博客到Github上
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
    <div class="article-category tagcloud">
    <a class="article-category-link" href="/blog/categories/工具使用/">工具使用</a>
    </div>


        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/Hexo/">Hexo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/Travis-CI/">Travis CI</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/github-blog/">github_blog</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/持续集成/">持续集成</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/自动部署/">自动部署</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
      
          
        <h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>这年头要是没有个博客都不好意思给别人说你是程序员，我用XX笔记呀，不行吗？不行，这玩意儿要么不能公开分享，要么公开分享要会员，现在到处都是开源，自己学到了东西都不能分享给需要帮助的人，真是伤心呀。那么今天就来聊聊当你用Hexo搭建了博客，怎么自动更新呢，大家都知道Hexo是需要手动生成HTML静态网页的，虽然命令很少，但是每次写完博客先得推送到git然后在生成静态文件，再推送到服务器，想想我这个心也是醉了，不过看到知乎上还有人带着U盘，我只能呵呵了~，你们耐心真好~</p>
<p>那我们今天就来说说怎么使用Travis CI来自动构建你的博客</p>
<h2 id="什么是Travis-CI"><a href="#什么是Travis-CI" class="headerlink" title="什么是Travis CI"></a>什么是Travis CI</h2><blockquote>
<p>Travis CI 是目前新兴的开源持续集成构建项目，它与jenkins，GO的很明显的特别在于采用yaml格式，同时他是在在线的服务，不像jenkins需要你本地打架服务器，简洁清新独树一帜。目前大多数的github项目都已经移入到Travis CI的构建队列中，据说Travis CI每天运行超过4000次完整构建。对于做开源项目或者github的使用者，如果你的项目还没有加入Travis CI构建队列，那么我真的想对你说out了。</p>
</blockquote>
<h2 id="我的博客架构"><a href="#我的博客架构" class="headerlink" title="我的博客架构"></a>我的博客架构</h2><p>也算是一个框架吧</p>
<p>首先我的博客是使用Hexo来搭建的，托管到Github提供的Gitpage服务上的</p>
<p>每次写完博客git push到github，然后Travis自动构建，构建完成后自动推送到Gitpage服务上</p>
<p>生成后的HTML文件和博客的源文件我是放到一个仓库的，只是使用了不同的分支</p>
<p>master：博客的静态文件，也就是hexo生成后的HTML文件，因为要使用Gitpage服务，所以他规定的网页文件必须是在master分支</p>
<p>blog-source：是博客的源代码</p>
<p>当然这样做有隐私问题，因为任何人都能哪的你的博客源码，当然既然是博客，所以就没有这些问题了</p>
<h2 id="启用要构建的项目"><a href="#启用要构建的项目" class="headerlink" title="启用要构建的项目"></a>启用要构建的项目</h2><p>首先如果你要使用Travis CI，你必须要GIthub账号（好像Travis CI只支持构建github的项目）和一个项目</p>
<p>使用Github账号登录<a href="https://travis-ci.org/" target="_blank" rel="external">Travis CI官网</a></p>
<p>点击My Repositories旁边的+，意思是添加一个要自动构建的仓库.</p>
<p>可以看到这个界面会显示当前github账号的所以项目，如果没有显示，点击右上角的“Sync account”按钮，就可以同步过来了（ps：上次用windows电脑始终同步不过来项目，最后换成mac可以同步了，最后又换回windows也可以了，汗(⊙﹏⊙)b，不太懂，什么个情况）</p>
<p>居然仓库都同步过来了，那么下一步肯定是要开启你需要构建的仓库，可以看到我开启了yourname.github.io这个项目，当然这个也是我就是我的博客啦</p>
<p>开启后我们还需要进行一些配置，操作如下</p>
<p>点击红框的那个菜单按钮，就会出现这样的下拉菜单，我们选择设置，来到这个界面，我们按照如下勾选</p>
<p>Build only if .travis.yml is present：是只有在.travis.yml文件中配置的分支改变了才构建<br>Build pushes：当推送完这个分支后开始构建</p>
<p>到这一步， 我们已经开启了要构建的仓库，但是还有个问题就是，构建完后，我们怎么将生成的文件推送到github上呢，如果不能推送那我们就不需要倒腾一番来使用Travis CI服务了，我们要的结果就是，我们只要想github一push，他就自动构建并push静态文件到gitpages呢，那么下面要解决的就是Travis CI怎么访问github了</p>
<h2 id="在Travis-CI配置Github的Access-Token"><a href="#在Travis-CI配置Github的Access-Token" class="headerlink" title="在Travis CI配置Github的Access Token"></a>在Travis CI配置Github的Access Token</h2><p>标题已经说得很明白了吧，我们需要在Travis上配置Access Token，这样我们就可以在他构建完后自动push到gitpgaes了，到这里肯定有人要问了，咋你把用户名密码直接写文件里呢，如果你真有这样的问题，那我只能说呵呵~，但我要告诉你的是写里面肯定是可以push成功的</p>
<h3 id="在github上生成Access-Token"><a href="#在github上生成Access-Token" class="headerlink" title="在github上生成Access Token"></a>在github上生成Access Token</h3><p>首先我们来到github的设置界面，点击到Personal access tokens页面，点击右上角的Generate new token按钮会重新生成一个，点击后他会叫你输入密码，然后来到如下界面，给他去一个名字，下面是勾选一些权限</p>
<p>生成完后，你需要拷贝下来，只有这时候他才显示，下载进来为了安全他就不会显示了，如果忘了只能重新生成一个了，拷贝完以后我们需要到Travis CI网站配置下</p>
<h3 id="在Travis-CI配置"><a href="#在Travis-CI配置" class="headerlink" title="在Travis CI配置"></a>在Travis CI配置</h3><p>配置界面还是在项目的setting里面</p>
<p>至于为什么我们要在这里配置，我想大家肯定应该明白了，写在程序里不安全，配置到这里相当于一个环境变量，我们在构建的时候就可以引用他。<br>到这里我已经配置了要构建的仓库和要访问的Token，但是问题来了，他知道怎么构建，怎么生成静态文件吗，怎么push的gitpages，又push到那个仓库吗，所以这里我们还需要在源代码的仓库里创建一个.travis.yml配置文件，放到源代码的根目录</p>
<p>其中内容如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div></pre></td><td class="code"><pre><div class="line">language: node_js</div><div class="line">node_js: stable</div><div class="line"></div><div class="line"># S: Build Lifecycle</div><div class="line">install:</div><div class="line">  - npm install</div><div class="line"></div><div class="line"></div><div class="line">#before_script:</div><div class="line"> # - npm install -g gulp</div><div class="line"></div><div class="line">script:</div><div class="line">  - hexo g</div><div class="line"></div><div class="line">after_script:</div><div class="line">  - cd ./public</div><div class="line">  - git init</div><div class="line">  - git config user.name &quot;yourname&quot;</div><div class="line">  - git config user.email &quot;yourname@gmail.com&quot;</div><div class="line">  - git add .</div><div class="line">  - git commit -m &quot;Update docs&quot;</div><div class="line">  - git push --force --quiet &quot;https://$&#123;GH_TOKEN&#125;@$&#123;GH_REF&#125;&quot; master:master</div><div class="line"># E: Build LifeCycle</div><div class="line"></div><div class="line">branches:</div><div class="line">  only:</div><div class="line">    - blog-source</div><div class="line">env:</div><div class="line"> global:</div><div class="line">   - GH_REF: github.com/yourname/yourname.github.io.git</div></pre></td></tr></table></figure>
<p>其中给你需要更换的又git config后面的配置信息<br>GH_REF的值更改为你的仓库地址</p>
<p>到这一步我们配置已经完成了，现在就是见证奇迹的时候了</p>
<h2 id="Push文章到Github"><a href="#Push文章到Github" class="headerlink" title="Push文章到Github"></a>Push文章到Github</h2><p>到这一步，我们可以写一篇文章，添加到你的博客的_posts目录下</p>
<p>然后commit并push到你的Github上</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push origin blog-source:blog-source</div></pre></td></tr></table></figure>
<p>如果不出意外，我们可以就可以在Travis CI网站看到他已经在构建了</p>
<p>构建完成。</p>

      
    </div>
    
  </div>
  
    
    <div class="copyright">
        <p><span>本文标题:</span><a href="/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/">手把手教你使用Travis CI自动部署你的Hexo博客到Github上</a></p>
        <p><span>文章作者:</span><a href="/" title="访问 maobaolong 的个人博客">maobaolong</a></p>
        <p><span>发布时间:</span>2017-01-20, 13:56</p>
        <p><span>最后更新:</span>2017-01-20, 14:07</p>
        
            <p>
                <span>更新历史:</span><i class="fa fa-github"></i>
                <a href="https://github.com/MOxFIVE/Markdown-Archives-Backup/blame/master/_posts/2017-01-20.工具使用/github_blog/github_hexo_travis.md" title="顺序查看文章各部分修改记录" target = "_blank">Blame</a>,
                <a href="https://github.com/MOxFIVE/Markdown-Archives-Backup/commits/master/_posts/2017-01-20.工具使用/github_blog/github_hexo_travis.md" title="查看文章有关更新记录" target = "_blank">History</a><span class="raw">文本模式:</span><i class="fa fa-file-text-o"></i>
                <a href="https://raw.githubusercontent.com/MOxFIVE/Markdown-Archives-Backup/master/_posts/2017-01-20.工具使用/github_blog/github_hexo_travis.md" title="查看 & 下载文章 Markdown 原始文本" target = "_blank"> .md Raw</a>
            </p>
        
        <p>
            <span>原始链接:</span><a class="post-url" href="/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/" title="手把手教你使用Travis CI自动部署你的Hexo博客到Github上">/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/</a>
            <span class="copy-path" data-clipboard-text="原文: /blog/2017/01/20/工具使用/github_blog/github_hexo_travis/　　作者: maobaolong" title="点击复制文章链接"><i class="fa fa-clipboard"></i></span>
            <script> var clipboard = new Clipboard('.copy-path'); </script>
        </p>
        <p>
            <span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" title="中国大陆 (CC BY-NC-SA 3.0 CN)" target = "_blank">"署名-非商用-相同方式共享 3.0"</a> 转载请保留原文链接及作者。
        </p>
    </div>

    
    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/blog/2017/01/29/技术学习/protobuffers/">
                    Proto Buffers
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/blog/2017/01/20/工具使用/github_blog/Yilia源码目录结构及构建须知/">
                    Yilia源码目录结构及构建须知
                </a>
            </div>
        
    </nav>

  
</article>






    <div id="toc" class="toc-article">
        <strong class="toc-title">文章目录</strong>
        
            <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#简介"><span class="toc-number">1.</span> <span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#什么是Travis-CI"><span class="toc-number">2.</span> <span class="toc-text">什么是Travis CI</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#我的博客架构"><span class="toc-number">3.</span> <span class="toc-text">我的博客架构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#启用要构建的项目"><span class="toc-number">4.</span> <span class="toc-text">启用要构建的项目</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#在Travis-CI配置Github的Access-Token"><span class="toc-number">5.</span> <span class="toc-text">在Travis CI配置Github的Access Token</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#在github上生成Access-Token"><span class="toc-number">5.1.</span> <span class="toc-text">在github上生成Access Token</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#在Travis-CI配置"><span class="toc-number">5.2.</span> <span class="toc-text">在Travis CI配置</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Push文章到Github"><span class="toc-number">6.</span> <span class="toc-text">Push文章到Github</span></a></li></ol>
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

    <script>
        yiliaConfig.toc = ["隐藏目录", "显示目录", !!"true"];
    </script>



    
    <div class="share">
        <div class="bdsharebuttonbox">
            <a href="#" class="fa fa-twitter bds_twi" data-cmd="twi" title="分享到推特"></a>
            <a href="#" class="fa fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="fa fa-qq bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a>
            <a href="#" class="fa fa-files-o bds_copy" data-cmd="copy" title="复制网址"></a>
            <a href="#" class="fa fa fa-envelope-o bds_mail" data-cmd="mail" title="通过邮件分享"></a>
            <a href="#" class="fa fa-weixin bds_weixin" data-cmd="weixin" title="生成文章二维码"></a>
            <a href="#" class="fa fa-share-alt bds_more" data-cmd="more"></i></a>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"手把手教你使用Travis CI自动部署你的Hexo博客到Github上　| maobaolong　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='https://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    </div>




    
      <div class="duoshuo" id="comments">
    <div id="comment-box" ></div>
    <div class="ds-thread" id="ds-thread" data-thread-key="2017/01/20/工具使用/github_blog/github_hexo_travis/" data-title="手把手教你使用Travis CI自动部署你的Hexo博客到Github上" data-url="/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/"></div>
    <script>
        var duoshuoQuery = {short_name:"maobaolong"};
        function loadComment() {
            var d = document, s = d.createElement('script');
            s.src = '//moxfive.xyz/resources/embed.js';
            s.async = true; s.charset = 'UTF-8';
            (d.head || d.body).appendChild(s);
        }

        $(function() { 
            var jsonUrl = "http://api.duoshuo.com/threads/counts.jsonp?short_name=maobaolong&threads=2017/01/20/工具使用/github_blog/github_hexo_travis/&callback=?";
            $.getJSON(jsonUrl, function(result) {
                $.each(result.response, function(i, field) {
                    var value = field.comments;
                    if (value > 0) {
                        $(".count-comment").text(value);
                        return;
                    }
                })

            })
        });
    </script>
    
    <aside class="comment-bar">
        <a href="javascript:void(0);">
            <i class="fa fa-commenting-o animated infinite pulse"></i>
            <i class="fa fa-spinner fa-pulse"></i>
            <span class="count-comment"></span>
        </a>
    </aside>

    <script>
        var $commentBar = $("#comments aside.comment-bar");
        var load$hide = function(){
            $commentBar.find("a > i").toggle();
            loadComment();
            $commentBar.fadeOut(800);
        }
        $commentBar.click(function(){
            load$hide();
        })
        $commentBar.children("a").hover(function(){
            load$hide();
        })
        if (window.location.hash === "#comments") {
            load$hide();
        }
    </script>

</div>

    




    <div class="scroll" id="post-nav-button">
        
            <a href="/blog/2017/01/29/技术学习/protobuffers/" title="上一篇: Proto Buffers">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/blog/2017/01/20/工具使用/github_blog/Yilia源码目录结构及构建须知/" title="下一篇: Yilia源码目录结构及构建须知">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/29/技术学习/protobuffers/">Proto Buffers</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/20/工具使用/github_blog/github_hexo_travis/">手把手教你使用Travis CI自动部署你的Hexo博客到Github上</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/20/工具使用/github_blog/Yilia源码目录结构及构建须知/">Yilia源码目录结构及构建须知</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/20/工具使用/github_blog/使用hexo创建github博客使用yelee主题/">使用hexo创建github博客使用yelee主题</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/18/技术学习/bigdata/alluxio/alluxio-rpc/">alluxio rpc 分析</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/18/技术学习/bigdata/alluxio/alluxio-层次化存储简介/">alluxio 层次化存储简介(转)</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/18/技术学习/bigdata/alluxio/alluxio-定位策略/">alluxio 定位策略(转)</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/18/技术学习/bigdata/alluxio/alluxio-protobuffers/">alluxio Proto Buffers</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/18/技术学习/bigdata/alluxio/alluxio-rpc-en/">alluxio rpc analysis</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/17/技术学习/bigdata/alluxio/alluxio-heartbeat/">alluxio heartbeat分析</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2017/01/09/技术学习/thrift/">rpc</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/16/技术学习/bigdata/hive/hive/">hive命令</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/16/技术学习/bigdata/saltstack-minion/">saltstack-minion</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/16/技术学习/bigdata/spark/spark/">hive命令</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/16/技术学习/bigdata/常用端口/">大数据常用端口</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/15/技术学习/树莓派/树莓派接人体感应传感器/">树莓派接人体感应传感器</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/13/技术学习/bigdata/alluxio/alluxio/">alluxio介绍与安装</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/12/01/技术学习/linux/Linux下文件类型及表示颜色/">Linux下文件类型及表示颜色</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/25/育儿经/健康知识/">健康知识</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/25/育儿经/元宝/">元宝</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/25/技术学习/树莓派/ownCloud安装/">树莓派上ownCloud的安装</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/24/技术学习/web/jquery中attr和prop的区别/">jquery中attr和prop的区别（转）</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/21/工具使用/idea/">idea</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/16/工具使用/maven/">maven</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/数据库/mysql 语法/">mysql sql语法</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/tomcat/">tomcat</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/linux/centos/">CENTOS笔记</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/linux/ubuntu/">ubuntu</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/jenkins/">jenkins</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/web/xss攻击_跨域攻击/">xss攻击</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/linux/linux 常用命令/">linux命令</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/数据库/mongodb/">mongodb</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/web/springMVC/">springMVC</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/kafka/">kafka</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/web/velocity/">velocity</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/数据库/mysql/">mysql</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/seafile/">seafile</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/树莓派/安装后/">树莓派安装后需要做的几件事</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/树莓派/常用命令/">树莓派常用命令</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/zookeeper/">zookeeper</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/web/html/">html</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/velocity/">velocity</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/web/playframework/">playframework</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/linux/shell脚本/">shell脚本</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/正则表达式/">正则表达式</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/git/">git</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/scrt/">scrt 破解和使用</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/haproxy/">haproxy</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/bigdata/hadoop/hadoop_rest/">hadoop_rest</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/nginx/">nginx</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/etcd/">etcd</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/工具使用/vim/">vim</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/web/jquery/">jquery</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/java/java/">java 远程调试</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/bigdata/hadoop/hadoop/">hadoop 命令</a></li><li class="post-list-item"><a class="post-list-link" href="/blog/2016/11/09/技术学习/bigdata/hadoop/yarn/fair-scheduler/">fair-scheduler</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                2015-2017 maobaolong
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题 v3.5">Yelee</a><span> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
    <script src="/blog/js/GithubRepoWidget.js"></script>

<script data-main="/blog/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 4;
                var backgroundimg = "url(/blog//background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
             github: ".github-widget a", 
            
             post: ".article-entry a[href]", 
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>